//
//  YeeCollectionVC.m
//  YeeShopProject
//
//  Created by CoderYee on 2017/3/7.
//  Copyright © 2017年 CoderYee. All rights reserved.
//

#import "YeeCollectionVC.h"
#import "YeeCollectionViewModel.h"
#import "YeeCollectionTableViewCell.h"
#import "YeeCollectionEntity.h"

@interface YeeCollectionVC ()
{
    NSMutableArray  *_dataArray;
    
}
@end

@implementation YeeCollectionVC

- (void)viewDidLoad
{
    [super viewDidLoad];
}
-(void)addOwnViews
{
    [super addOwnViews];
}
-(void)addNavbarView
{
    [super addNavbarView];
    self.title=@"收藏";
}
-(void)configOwnViews
{
    [super configOwnViews];
    _dataArray=[[NSMutableArray alloc] init];
    [self.view setBackgroundColor:xBackgroundColor];
    [self.tableView setBackgroundColor:xBackgroundColor];
    self.tableView.separatorColor=[UIColor clearColor];
}
-(void)bindViewModel
{
    [super bindViewModel];
    
    @weakify(self);
    YeeCollectionViewModel *viewModel=[[YeeCollectionViewModel alloc] init];
    RACSignal * signal=[viewModel.command execute:nil];
    [signal subscribeNext:^(NSArray *dataArray)
    {
        @strongify(self);
        if (_dataArray.count!=0)
        {
            [_dataArray removeAllObjects];
        }
        [_dataArray addObjectsFromArray:dataArray];;
        [self tableViewEndRefresh];
    }];
    //获取 到错误信息
    [signal subscribeError:^(NSError * _Nullable error)
    {
       @strongify(self);
        [self.view showNBErrorMessage:@"网络错误"];
        
    }];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YeeCollectionTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YeeCollectionTableViewCell class])];
    if (cell==nil)
    {
        cell=[[YeeCollectionTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([YeeCollectionTableViewCell class])];
    }
    YeeCollectionEntity *Entity=_dataArray[indexPath.row];
    
    cell.Entity=Entity;
    
    return cell;
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc] init];
    return view;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kMainScreenWidth, 0.01)];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    YeeCollectionEntity *Entity=_dataArray[indexPath.row];
    NSLog(@"%f",Entity.cellHeight);
    return Entity.cellHeight;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
